class OrderedStream(object):

    def __init__(self, n):
        """
        :type n: int
        """
        self.p = [''] * n
        self.ptr = 0
        self.n = n


    def insert(self, idKey, value):
        """
        :type idKey: int
        :type value: str
        :rtype: List[str]
        """
        self.p[idKey - 1] = value
        if idKey - 1 == self.ptr:
            out = []
            while self.ptr < self.n and self.p[self.ptr]:
                out.append(self.p[self.ptr])
                self.ptr += 1
            return out
        else:
            return []
